<template>
  <div class="article-page">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>面经后台</el-breadcrumb-item>
      <el-breadcrumb-item>面经管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card shadow="never" border="false">
      <template #header>
        <div class="header">
          <span>共 300 条记录</span>
          <el-button
            icon="el-icon-plus"
            size="small"
            type="primary"
            round>
            添加面经
          </el-button>
        </div>
       <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="date"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
       <el-table-column
        prop="gnder"
        label="性别"
        width="180">
        <template v-slot="{row}">
         {{ getGender(row.gender) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        label="操作">
          <!-- 这里就是插槽的位置 -->
          <!-- 作用域插槽: 获取组件内传递过来的数据 -->
          <!-- <slot :item="" :row=""></slot> => obj: { item, row } -->
        <template v-slot="{ row }">
      <el-button @click="del(row.id)" type="primary">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
      </template>

    </el-card>
  </div>
</template>

<script>
export default {
  name: 'article-page',
  data () {
    return {
      tableData: [{
        id: 1,
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄',
        gnder: 1
      }, {
        id: 2,
        date: '2016-05-04',
        name: '王小花',
        address: '上海市普陀区金沙江路 1517 弄',
        gnder: 0
      }, {
        id: 3,
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄',
        gnder: 1
      }, {
        id: 4,
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄',
        gnder: 1
      }]
    }
  },
  created () {
  },
  methods: {
    del (id) {
      // console.log('我被点了', id)
      // 根据 id 找索引
      const index = this.tableData.findIndex(item => item.id === id)
      // 根据索引删除数据
      this.tableData.splice(index, 1)
    },
    getGender (code) {
      // console.log(code)
      // if (code === 0) {
      //   return '女'
      // } else if (code === 1) {
      //   return '男'
      // } else {
      //   return '妖'
      // }
      // 数据字典 => 高级的思想
      // const obj = {
      //   0: '女',
      //   1: '男',
      //   2: '妖'
      // }
      // return obj[code]
      // const arr = ['女', '男', '妖']
      // return arr[code]
      // const arr = ['女', '男', '妖']
      return ['女', '男', '妖'][code]
    }
  }
}
</script>

<style lang="scss" scoped>
.el-card {
  margin-top: 25px;
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 16px;
  }
  .actions {
    font-size: 18px;
    display: flex;
    justify-content: space-around;
    color: #666;
    > i:hover {
      color: rgba(114, 124, 245, 1);
      cursor: pointer;
    }
  }
}
.el-pagination {
  margin-top: 20px;
  text-align: center;
}
.el-breadcrumb {
  margin-top: 10px;
}
.el-form {
  padding-right: 40px;
}
.quill-editor {
  ::v-deep .ql-editor {
    height: 300px;
  }
}
.el-rate {
  padding: 10px 0;
}
.article-preview {
  padding: 0 40px 40px 40px;
  > h5 {
    font-size: 20px;
    color: #666;
    border-bottom: 1px dashed #ccc;
    padding-bottom: 30px;
    margin: 0 0 20px 0;
  }
}
</style>
